package com.chenxinzhimusic.viewmodel

import android.content.Context
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.chenxinzhimusic.data.loveKey
import com.chenxinzhimusic.data.playListKey
import com.chenxinzhimusic.entity.PlayList
import com.chenxinzhimusic.entity.getMusic
import com.chenxinzhimusic.refreshFlow
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class PlayListViewModel(app: Context) : ViewModel() {
    val type = listOf("我喜欢", "播放列表")

    var playListD: PlayList? by mutableStateOf(null)
    var loveList: PlayList? by mutableStateOf(null)


    init {
        viewModelScope.launch(Dispatchers.IO) {
            with(app) {
                refreshFlow.collect {
                    playListD =
                        getMusic(playListKey)
                    loveList = getMusic(loveKey)

                }

            }

        }
    }


    override fun onCleared() {

    }
}